package com.linian.pushforcampus.config;

import com.linian.pushforcampus.domain.PushConfigure;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * packageName com.linian.pushforcampus.config
 *
 * @author Lennon
 * @className TemplateConfig
 * @date 2023/11/20
 * @description TODO
 */

@Configuration
public class TemplateConfig {

    @Autowired
    private PushConfigure pushConfigure;


    /**
     * 微信服务装载
     * @return
     */
    @Bean
    public WxMpService wxMpService() {
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
        return wxMpService;
    }

    /**
     * 配置温馨的APPID和密码
     * @return
     */
    @Bean
    public WxMpConfigStorage wxMpConfigStorage() {
        WxMpInMemoryConfigStorage wxMpConfigStorage = new WxMpInMemoryConfigStorage();
        wxMpConfigStorage.setAppId(pushConfigure.getAppId());
        wxMpConfigStorage.setSecret(pushConfigure.getSecret());
        return wxMpConfigStorage;
    }

}
